//
//  ViewController.m
//  KVO实现机制
//
//  Created by MyMac on 15/8/28.
//  Copyright (c) 2015年 tongfang. All rights reserved.
//

#import "ViewController.h"
#import "NSObject+KVO.h"
#import "Person.h"
#import <objc/runtime.h>
#import <objc/message.h>
@interface ViewController ()
@property(nonatomic,strong)Person*per;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    Person*p1=[[Person alloc]init];
    self.per=p1;

    [p1 addobserver:self andKey:@"name" andBlock:^(id key, id newValue, id oldValue) {
        NSLog(@"key:%@\n new:%@\n old:%@",key,newValue,oldValue);
    }];
    p1.name=@"xinzhi";
    NSLog(@"new:%@",p1.name);
    p1.name=@"123231";
   NSLog(@"new:%@",p1.name);

}
- (IBAction)btnCLick:(id)sender {
self.per.name=[NSString stringWithFormat:@"%ld",(long)arc4random()];
int value=  func(1,"11111");
    NSLog(@"%d******%@",value,self.per.name);
   
    
    
    
    
    
    SEL sel=@selector(sendMessage);
 
    
    
    
    
    NSString*str=   objc_msgSend(self, sel);

    NSLog(@"%@",str);
}
//c函数调用
int func (int i,char*name){
    return arc4random();

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSString*)sendMessage
{
    
 return @"113334";

}
@end
